<?php
if (empty($_COOKIE['admin_id'])){
    echo "尚未登录,请先登录";
    echo "<a href='login.php'>登录</a>";
    exit();
}

date_default_timezone_set("prc");
//设定用于一个脚本中所有日期时间函数的默认时区说明
//$servername = "127.0.0.1";
//$username = "root";
//$password = "123456";
//try {
//    $conn = new PDO("mysql:host=$servername;", $username, $password);
//    echo "连接成功";
//}
//catch(PDOException $e)
//{
//    echo $e->getMessage();
//}
$dsn = "mysql:host=127.0.0.1;dbname=blog";
$db = new pdo($dsn,"root","123456");
$db->exec("set names utf8mb4");
$sql = "select * from category order by category_id asc ";
$result = $db->query($sql);
$categoryList = $result->fetchAll(pdo::FETCH_ASSOC);
//var_dump($categoryList);
//exit();

?>
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="css/base.css" />
		<link rel="stylesheet" type="text/css" href="css/top.css" />
		<link rel="stylesheet" type="text/css" href="css/right.css" />
		<link rel="stylesheet" type="text/css" href="css/left.css" />
	</head>
	<body>
		<div id="container">
		    <div id="top">
				<div id="top_left">
					<span>博客管理系统</span>
				</div>
				<div id="top_right">
    欢迎你：admin <a href="logout.php">退出登录</a>
				</div>
		    </div>
			<div id="left">
				<ul>
					<li><a href="#" id="left_one">分类管理</a></li>
					<li><a href="#">文章管理</a></li>
					<li><a href="#">管理员</a></li>
				</ul>
			</div>
		    <div id="right">
				<ul>
					<li>
						<a href="#">首页</a>&nbsp;>
						<a href="#">分类管理</a>&nbsp;>
						<a href="#">分类列表</a>
					</li>
					<li>
						<button id="all">全选</button>
						<a id="multi_delete" href="#">删除选中分类</a>
						<a id="add" href="category_add.php" style="float: right">增加分类</a>
					</li>
					<li>
						<form id="multi-delete-form" action="#">
						    <table class="list">
						        <tbody>
						        <tr>
						            <th></th>
						            <th>分类ID</th>
						            <th>分类名称</th>
									<th>分类简介</th>
						            <th>修改时间</th>
						            <th>增加时间</th>
						            <th>操作</th>
						        </tr>
                                <?php foreach ($categoryList as $item): ?>
						        <tr>
						            <td><input type="checkbox"></td>
						            <td><?php echo $item['category_id'] ?></td>
						            <td><?php echo $item['category_name'] ?></td>
									<td><?php echo $item['category_desc'] ?></td>
						            <td><?php echo date("Y-m-d H:i:s",$item['update_time']) ?></td>
						            <td><?php echo date("Y-m-d H:i:s",$item['add_time']) ?></td>
						            <td>
						                <a class="update" href="category_edit.php?category_id=<?php echo $item['category_id'] ?>">编辑</a>
						                <a class="delete" href="category_delete.php?category_id=<?php echo $item['category_id'] ?>">删除</a>
						            </td>
						        </tr>
                                <?php endforeach; ?>
						        </tbody>
						    </table>
						</form>
					</li>
				</ul>
			</div>
		</div>
	</body>
</html>
